/**
 * 待办通知表 编辑页
 *
 * 作者 ganjun
 * 日期 2024-11-30 21:43:28
 */
layui.use(['jquery','febs', 'form', 'validate'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        $view = $('#notice-edit'),
        validate = layui.validate;

    form.verify(validate);
    form.render();
    initFormValue();

    function initFormValue() {
        if (noticeData) {
            form.val("notice-edit-form", {
                "id": noticeData.id,
                "noticeType": noticeData.noticeType,
                "noticeTitle": noticeData.noticeTitle,
                "noticeContent": noticeData.noticeContent,
                "sendDate": noticeData.sendDate,
                "receiveDate": noticeData.receiveDate,
                "receiveUserId": noticeData.receiveUserId,
                "receiveRealName": noticeData.receiveRealName,
                "status": noticeData.status,
            });
        }
    }

    form.on('submit(notice-edit-form-submit)', function (data) {
        addOrUpdate(data.field);
        return false;
    });

    function addOrUpdate(data) {
        febs.modal.confirm("保存提示！","是否保存？",function (index){
            if (data.id && data.id.length > 0) {
                febs.postArray(ctx + 'notice/update', data, function () {
                    layer.closeAll();
                    febs.alert.success('修改成功');
                    febs.reloadPage();
                });
            } else {
                febs.postArray(ctx + 'notice', data, function () {
                    layer.closeAll();
                    febs.alert.success('新增成功');
                    $('#febs-notice').find('#query').trigger('click');
                });
            }
        })
    }
});